package com.gjw.cor;

import com.gjw.planeWar.EnemyDir;
import com.gjw.planeWar.EnemyPlane;
import com.gjw.planeWar.GameObject;
import utils.EnumUtil;

import java.util.Objects;

/**
 * @author gjw19
 * @date 2019/5/19
 */
public class EnemyEnemyCollider implements Collider {
    @Override
    public boolean collide(GameObject o1, GameObject o2) {
        if (o1 instanceof EnemyPlane && o2 instanceof EnemyPlane) {
            EnemyPlane e1 = (EnemyPlane) o1;
            EnemyPlane e2 = (EnemyPlane) o2;
            if (e1.getRect().intersects(e2.getRect()) && !Objects.equals(e1, e2)) {
                e1.setEnemyDir(EnumUtil.randomEnumExclude(EnemyDir.class, e1.getEnemyDir()));
                e2.setEnemyDir(EnumUtil.randomEnumExclude(EnemyDir.class, e2.getEnemyDir()));
            }
        }
        return true;
    }
}
